package com.shigu.appVersion.service;

import com.opentae.data.mall.beans.ManagerPageConstant;
import com.opentae.data.mall.examples.ManagerPageConstantExample;
import com.opentae.data.mall.interfaces.ManagerPageConstantMapper;
import com.shigu.PageResponse;
import com.shigu.appVersion.utils.AppVersionUtil;
import com.shigu.appVersion.vo.DownLoadResponse;
import com.shigu.appVersion.vo.SomethingResponse;
import com.shigu.appVersion.vo.VersionResponse;
import com.shigu.constant.enums.PageUri;
import com.shigu.constant.enums.VersionCtrl;
import com.shigu.constant.service.SystemConstantService;
import com.shigu.user.OSS.OssIO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/*
 * create by  过儿  2019-06-19
 *
 */
@Service
public class AdminVersionService {

    @Autowired
    ManagerPageConstantMapper managerPageConstantMapper;
    @Autowired
    OssIO ossIO;

    @Value("${filePath}")
    private String apkPath;

    /**
     * @description 查询与手机系统无关的常量
     * @author 郭尔
     * @date 2019-07-02 9:59
     */
    public PageResponse<ManagerPageConstant> getVersionConstant() {

        ManagerPageConstantExample example = new ManagerPageConstantExample();
        ManagerPageConstantExample.Criteria criteria1 = example.createCriteria();
        ManagerPageConstantExample.Criteria criteria2 = example.createCriteria();
        criteria1.andPageUriEqualTo(PageUri.vip.toString());
        criteria2.andPageUriEqualTo(PageUri.version.toString());

        example.or(criteria2);

        List<ManagerPageConstant> constants = managerPageConstantMapper.selectByExample(example);

        PageResponse<ManagerPageConstant> response = new PageResponse<>();
        response.setData(constants);

        return response;
    }

    /**
     *
     * @description 查询不同端的参数
     * @author 郭尔
     * @date 2019-07-02 10:15
     */
     public PageResponse<ManagerPageConstant> selOsConstant(String pageUri){
         ManagerPageConstantExample example = new ManagerPageConstantExample();
         example.createCriteria().andPageUriEqualTo(pageUri);
         example.setOrderByClause("constant_id desc");
         List<ManagerPageConstant> constants = managerPageConstantMapper.selectByExample(example);
         PageResponse<ManagerPageConstant> response = new PageResponse<>();
         response.setData(constants);
         return response;
     }
    /**
     *
     * @description 上传安卓安装包
     * @author 郭尔
     * @date 2019-07-03 13:51
     */
    public void uploadApk(String url){

        ManagerPageConstantExample example = new ManagerPageConstantExample();
        example.createCriteria().andFieldNameEqualTo(VersionCtrl.androidUrl.toString());

        ManagerPageConstant constant = new ManagerPageConstant();
        constant.setFieldValue(url);

        managerPageConstantMapper.updateByExampleSelective(constant,example);
    }
}